clear
use ReplicationData.dta

ssc install grstyle, replace 
ssc install palettes, replace
ssc install blindschemes, replace
ssc install asdoc, replace

label var nuclear "Nuclear weapons support (baseline)"

label var individ_nodefend_nuke "Individual nuclear support (refusal to defend)"
label var individ_conditional_nuke "Individual support (threat of abandon)"
label var individ_withdraw_nuke "Individual support (troop withdrawal)"
label var individ_spendinginc_nuke "Individual support (2x spending increase)"


label var govt_nodefend_nuke "Gov't nuclear likelihood (refusal to defend)"
label var govt_conditional_nuke "Gov't nuclear likelihood (threat of abandon)"
label var govt_withdraw_nuke "Gov't nuclear likelihood (troop withdrawal)"
label var govt_spendinginc_nuke "Gov't nuclear likelihood (2x spending increase)"


*Figure 1*
preserve
gen pair = _n
gen mean_diff = .
gen lowerci = .
gen upperci = .
ttest nuclear==individ_nodefend_nuke
replace mean_diff = r(mu_2) - r(mu_1) if pair==4
*scalar lb = mean_diff - invt(r(df_t), 0.975)*r(se)
*scalar ub = mean_diff + invt(r(df_t), 0.975)*r(se)
*scalar dir
replace lowerci = mean_diff - invt(r(df_t), 0.975)*r(se) if pair==4
replace upperci = mean_diff + invt(r(df_t), 0.975)*r(se) if pair==4
*gen lowerci2 = mean_diff - 1.96*r(se)

ttest nuclear==individ_conditional_nuke
replace mean_diff = r(mu_2) - r(mu_1) if pair==2
*scalar lb = mean_diff - invt(r(df_t), 0.975)*r(se)
*scalar ub = mean_diff + invt(r(df_t), 0.975)*r(se)
*scalar dir
replace lowerci = mean_diff - invt(r(df_t), 0.975)*r(se) if pair==2
replace upperci = mean_diff + invt(r(df_t), 0.975)*r(se) if pair==2


ttest nuclear==individ_withdraw_nuke
replace mean_diff = r(mu_2) - r(mu_1) if pair==3
*scalar lb = mean_diff - invt(r(df_t), 0.975)*r(se)
*scalar ub = mean_diff + invt(r(df_t), 0.975)*r(se)
*scalar dir
replace lowerci = mean_diff - invt(r(df_t), 0.975)*r(se) if pair==3
replace upperci = mean_diff + invt(r(df_t), 0.975)*r(se) if pair==3

ttest nuclear==individ_spendinginc_nuke
replace mean_diff = r(mu_2) - r(mu_1) if pair==1
*scalar lb = mean_diff - invt(r(df_t), 0.975)*r(se)
*scalar ub = mean_diff + invt(r(df_t), 0.975)*r(se)
*scalar dir
replace lowerci = mean_diff - invt(r(df_t), 0.975)*r(se) if pair==1
replace upperci = mean_diff + invt(r(df_t), 0.975)*r(se) if pair==1


grstyle init // initiates grstyle
grstyle set horizontal // set tick labels horizontal
grstyle set compact // overall design compact
grstyle set size small: subheading axis_title // subtitle and axis title set to small
grstyle set size vsmall: small_body // margin around notes
grstyle set legend 6, nobox //legend position on 6 o'clock, removes box
grstyle set linewidth thin: major_grid // set grid line thickness to thin
grstyle set linewidth thin: tick // set tick thickness to thin
grstyle set linewidth thin: axisline // set axislines thickness to thin
grstyle set linewidth vthin: xyline // reference line at 0
grstyle color background white // set overall background to white

set scheme plotplain

twoway (scatter pair mean_diff  if pair < 5 & pair != ., sort(pair) mcolor(black) xline(0, lpattern(dash))) ///
|| (rcap upperci lowerci pair if pair < 5 & pair != ., horizontal lcolor(black)), graphregion(fcolor(white)) scheme(white_tableau) ylabel(1 "2x Spending Increase" 2 "Conditional Threat" 3 "Troop Withdrawal" 4 "Refusal to Defend") xtitle("Differences in Means from Baseline (mean=1.88)") ytitle("") legend(off) xtick(-0.2(0.2)0.8) xlabel(-0.2(0.2)0.8)
*graph export "Figure1.jpg", replace as(jpg)  width(1000)
*graph export "Figure1.eps", replace
restore

*Figure 2*

preserve
gen pair = _n
gen mean_diff = .
gen lowerci = .
gen upperci = .
ttest  govt_spendinginc_nuke=govt_nodefend_nuke
replace mean_diff = r(mu_2) - r(mu_1) if pair==3
*scalar lb = mean_diff - invt(r(df_t), 0.975)*r(se)
*scalar ub = mean_diff + invt(r(df_t), 0.975)*r(se)
*scalar dir
replace lowerci = mean_diff - invt(r(df_t), 0.975)*r(se) if pair==3
replace upperci = mean_diff + invt(r(df_t), 0.975)*r(se) if pair==3
*gen lowerci2 = mean_diff - 1.96*r(se)

ttest  govt_spendinginc_nuke=govt_withdraw_nuke
replace mean_diff = r(mu_2) - r(mu_1) if pair==2
*scalar lb = mean_diff - invt(r(df_t), 0.975)*r(se)
*scalar ub = mean_diff + invt(r(df_t), 0.975)*r(se)
*scalar dir
replace lowerci = mean_diff - invt(r(df_t), 0.975)*r(se) if pair==2
replace upperci = mean_diff + invt(r(df_t), 0.975)*r(se) if pair==2


ttest  govt_spendinginc_nuke=govt_conditional_nuke
replace mean_diff = r(mu_2) - r(mu_1) if pair==1
*scalar lb = mean_diff - invt(r(df_t), 0.975)*r(se)
*scalar ub = mean_diff + invt(r(df_t), 0.975)*r(se)
*scalar dir
replace lowerci = mean_diff - invt(r(df_t), 0.975)*r(se) if pair==1
replace upperci = mean_diff + invt(r(df_t), 0.975)*r(se) if pair==1


grstyle init // initiates grstyle
grstyle set horizontal // set tick labels horizontal
grstyle set compact // overall design compact
grstyle set size small: subheading axis_title // subtitle and axis title set to small
grstyle set size vsmall: small_body // margin around notes
grstyle set legend 6, nobox //legend position on 6 o'clock, removes box
grstyle set linewidth thin: major_grid // set grid line thickness to thin
grstyle set linewidth thin: tick // set tick thickness to thin
grstyle set linewidth thin: axisline // set axislines thickness to thin
grstyle set linewidth vthin: xyline // reference line at 0
grstyle color background white // set overall background to white

set scheme plotplain

twoway (scatter pair mean_diff  if pair < 4 & pair != ., sort(pair) mcolor(black) xline(0, lpattern(dash))) ///
|| (rcap upperci lowerci pair if pair < 4 & pair != ., horizontal lcolor(black)), graphregion(fcolor(white)) scheme(white_tableau) ylabel(1 "Conditional Threat" 2 "Troop Withdrawal" 3 "Refusal to Defend") xtitle("Differences in Means from 2x Spending Increase Scenario (mean=1.55)") ytitle("") legend(off) xtick(-0.2(0.2)0.8) xlabel(-0.2(0.2)0.8)
*graph export "Figure2.jpg", replace as(jpg)  width(1000)
*graph export "Figure2.eps", replace
restore


*Figure 3a*

grstyle init // initiates grstyle
grstyle set horizontal // set tick labels horizontal
grstyle set compact // overall design compact
grstyle set size small: subheading axis_title // subtitle and axis title set to small
grstyle set size vsmall: small_body // margin around notes
grstyle set legend 6, nobox //legend position on 6 o'clock, removes box
grstyle set linewidth thin: major_grid // set grid line thickness to thin
grstyle set linewidth thin: tick // set tick thickness to thin
grstyle set linewidth thin: axisline // set axislines thickness to thin
grstyle set linewidth vthin: xyline // reference line at 0
grstyle color background white // set overall background to white


set scheme plotplain

preserve
replace country = "Slovakia" if country=="Slovak Republic"
replace country = "Netherlands" if country=="The Netherlands"
replace country = "Neth." if country=="Netherlands"
drop if country=="France"

foreach var in nonukes1_alliance nonukes1_intlnorms nonukes1_natlidentity  nonukes1_technical nonukes1_abandon nonukes1_nothreat nonukes1_sanctions nonukes1_preventive {
egen `var'_sum = sum(`var')
}
gen nonukes1_reason = "No Threat" if _n==1
replace nonukes1_reason = "Alliance w/ US" if _n==2
replace nonukes1_reason = "Technically Difficult" if _n==3
replace nonukes1_reason = "National Identity" if _n==4
replace nonukes1_reason = "Norms" if _n==5
replace nonukes1_reason = "US Abandonment" if _n==6
replace nonukes1_reason = "Sanctions" if _n==7
replace nonukes1_reason = "Preventive War" if _n==8
gen nonukes1_sum = nonukes1_alliance_sum if _n==2
replace nonukes1_sum = nonukes1_intlnorms_sum if _n==5
replace nonukes1_sum = nonukes1_natlidentity_sum if _n==4
replace nonukes1_sum = nonukes1_technical_sum if _n==3
replace nonukes1_sum = nonukes1_abandon_sum if _n==6
replace nonukes1_sum = nonukes1_nothreat_sum if _n==1
replace nonukes1_sum = nonukes1_sanctions_sum if _n==7
replace nonukes1_sum = nonukes1_preventive_sum if _n==8


*graph hbar (sum) nonukes1_alliance nonukes1_intlnorms nonukes1_natlidentity  nonukes1_technical nonukes1_abandon nonukes1_nothreat nonukes1_sanctions nonukes1_preventive if country != "France" & nuclear != ., graphregion(fcolor(white)) ytitle("Number of Respondents Citing Why their Country Has No NW Program", size(medium)) legend(lab(5 "No Threat") lab(1 "Alliance w/ US") lab(4 "Technically Difficult") lab(3 "National Identity") lab(2 "Norms") lab(7 "Sanctions") lab(8 "Preventive War") lab(6 "US Abandonment"))
graph hbar (sum) nonukes1_sum, over(nonukes1_reason, sort(nonukes1_sum) descending label(labsize(*0.8))) graphregion(fcolor(white)) ytitle("Number of Respondents Citing Why their Country Has No Nuclear Weapons Program", size(small))
*graph export "Figure3a.jpg", replace as(jpg)  width(1000)
*graph export "Figure3a.eps", replace
*eststo clear
restore

*Figure 3b*

grstyle init // initiates grstyle
grstyle set horizontal // set tick labels horizontal
grstyle set compact // overall design compact
grstyle set size small: subheading axis_title // subtitle and axis title set to small
grstyle set size vsmall: small_body // margin around notes
grstyle set legend 6, nobox //legend position on 6 o'clock, removes box
grstyle set linewidth thin: major_grid // set grid line thickness to thin
grstyle set linewidth thin: tick // set tick thickness to thin
grstyle set linewidth thin: axisline // set axislines thickness to thin
grstyle set linewidth vthin: xyline // reference line at 0
grstyle color background white // set overall background to white


set scheme plotplain

preserve
drop if country=="France"
keep nonukes2
duplicates drop nonukes2, force
gen nonukes2_num = 0 
replace nonukes2_num = 4 if nonukes2=="No need for them due to not facing a major foreign threat"
replace nonukes2_num = 48 if nonukes2=="No need for them due to the alliance with the United States"
replace nonukes2_num = 4 if nonukes2=="Producing nuclear weapons would be too difficult technically"
replace nonukes2_num = 18 if nonukes2=="Acquiring nuclear weapons would not be consistent with the country’s national identity"
replace nonukes2_num = 28 if nonukes2=="Acquiring nuclear weapons would not be consistent with international norms and international law"
replace nonukes2_num = 2 if nonukes2=="Pursuing nuclear weapons would cause the country to be abandoned by the United States"

replace nonukes2 = "No Threat" if nonukes2=="No need for them due to not facing a major foreign threat"
replace nonukes2 = "Alliance w/ US" if nonukes2=="No need for them due to the alliance with the United States"
replace nonukes2 = "Technically Difficult" if nonukes2=="Producing nuclear weapons would be too difficult technically"
replace nonukes2 = "National Identity" if nonukes2=="Acquiring nuclear weapons would not be consistent with the country’s national identity"
replace nonukes2 = "Norms" if nonukes2=="Acquiring nuclear weapons would not be consistent with international norms and international law"
replace nonukes2 = "US Abandonment" if nonukes2=="Pursuing nuclear weapons would cause the country to be abandoned by the United States"
insobs 2
replace nonukes2 = "Sanctions" if _n==8
replace nonukes2 = "Preventive War" if _n==9
replace nonukes2_num = 0 if _n==8
replace nonukes2_num = 0 if _n==9
graph hbar (sum) nonukes2_num, over(nonukes2, sort(nonukes2_num) descending label(labsize(*0.8))) graphregion(fcolor(white)) ytitle("Number of Respondents Citing Why their Country Has No Nuclear Weapons Program", size(small))
*graph export "Figure3b.jpg", replace as(jpg)  width(1000)
*graph export "Figure3b.eps", replace
*eststo clear
restore

*Figure 4*

preserve
grstyle init // initiates grstyle
grstyle set horizontal // set tick labels horizontal
grstyle set compact // overall design compact
grstyle set size small: subheading axis_title // subtitle and axis title set to small
grstyle set size vsmall: small_body // margin around notes
grstyle set legend 6, nobox //legend position on 6 o'clock, removes box
grstyle set linewidth thin: major_grid // set grid line thickness to thin
grstyle set linewidth thin: tick // set tick thickness to thin
grstyle set linewidth thin: axisline // set axislines thickness to thin
grstyle set linewidth vthin: xyline // reference line at 0
grstyle color background white // set overall background to white
set scheme plotplain

eststo clear
label var nonukes1_nothreat "Why no nukes: No threat"
label var nonukes1_abandon "Why no nukes: Would be abandoned by US"
label var nonukes1_technical "Why no nukes: Too technically difficult"
label var nonukes1_natlidentity "Why no nukes: Nat'l identity"
label var nonukes1_intlnorms "Why no nukes: Internat'l norms"
label var nonukes1_alliance "Why no nukes: Alliance w/ US"
label var nonukes1_preventive "Why no nukes: Fear of preventive attack"
label var nonukes1_sanctions "Why no nukes: Fear of sanctions"
eststo: reg govt_nodefend_nuke milspending_govt antimilitarism_govt safety_govt moscow nonukes1_nothreat-nonukes1_abandon
margins, at(nonukes1_alliance=(0(1)1)) atmeans predict(xb) coeflegend post
estimates store model1
eststo: reg govt_conditional_nuke milspending_govt antimilitarism_govt safety_govt moscow nonukes1_nothreat-nonukes1_abandon
margins, at(nonukes1_alliance=(0(1)1)) atmeans predict(xb) coeflegend post
estimates store model2
eststo: reg govt_withdraw_nuke milspending_govt antimilitarism_govt safety_govt moscow nonukes1_nothreat-nonukes1_abandon
margins, at(nonukes1_alliance=(0(1)1)) atmeans predict(xb) coeflegend post
estimates store model3
eststo: reg govt_spendinginc_nuke milspending_govt antimilitarism_govt safety_govt moscow nonukes1_nothreat-nonukes1_abandon
margins, at(nonukes1_alliance=(0(1)1)) atmeans predict(xb) coeflegend post
estimates store model4

coefplot model1, bylabel(Refusal to Defend Scenario) || model3, bylabel(Troop Withdrawal Scenario) || model2, bylabel(Conditional Threat Scenario) || model4, bylabel(2x Spending Increase Scenario)  ///
recast(bar) barw(0.15) vertical ylab(0(.1).7) ///
ciopts(recast(rcap) color(black%50)) citop ///
legend(order(1 "Reassurance" 3 "Abandonment" ///
5 "Conditional Pressure" 7 "Domestic Pressure")) ///
ytitle("Government Likelihood of Pursuing Nuclear Weapons") ///
xtitle("") bcolor(gray)  ///
xlabel(1 "US Alliance Not Important" 2 "US Alliance Important") ytick(0(0.5)3) ylabel(0(0.5)3) graphregion(fcolor(white)) yline(0, lpattern(dash) lstyle(foreground) lcolor(black)) scheme(white_tableau) xtick(1(1)2)  xscale(noline)
*graph export "Figure4.jpg", replace as(jpg)  width(1000)
*graph export "Figure4.eps", replace
eststo clear
restore

*Table A2*
sum age female male government_ever government_current nuclear if nuclear != .
*asdoc sum age female male government_ever government_current nuclear if nuclear != ., label replace save(Nonprolif_SumStats.rtf) 

*Table A3*
pwcorr nuclear milspending antimilitarism safety female age government_ever government_current moscow milexpergdp_2023
*asdoc pwcorr nuclear milspending antimilitarism safety female age government_ever government_current moscow milexpergdp_2023, label replace sig star(.05) save(Nonprolif_CorrMatrix_individ.rtf) font(Times New Roman)


*Table A4*
eststo clear
eststo: reg nuclear milspending
eststo: reg nuclear milspending antimilitarism safety moscow female agebracket government_ever2 government_current milexpergdp_2023
eststo: ologit nuclear milspending
eststo: ologit nuclear milspending antimilitarism safety moscow female agebracket government_ever2 government_current milexpergdp_2023
eststo clear

*Table A5*
eststo clear
eststo: reg govt_nodefend_nuke nonukes1_nothreat-nonukes1_abandon
eststo: reg govt_conditional_nuke nonukes1_nothreat-nonukes1_abandon
eststo: reg govt_withdraw_nuke nonukes1_nothreat-nonukes1_abandon
eststo: reg govt_spendinginc_nuke nonukes1_nothreat-nonukes1_abandon
eststo: ologit govt_nodefend_nuke nonukes1_nothreat-nonukes1_abandon
eststo: ologit govt_conditional_nuke nonukes1_nothreat-nonukes1_abandon
eststo: ologit govt_withdraw_nuke nonukes1_nothreat-nonukes1_abandon
eststo: ologit govt_spendinginc_nuke nonukes1_nothreat-nonukes1_abandon
eststo clear

*Table A6*

preserve

local vars individ_nodefend_nuke individ_conditional_nuke individ_withdraw_nuke individ_spendinginc_nuke  
local groupvar government_current      


foreach var in  individ_nodefend_nuke individ_conditional_nuke individ_withdraw_nuke individ_spendinginc_nuke govt_nodefend_nuke govt_conditional_nuke govt_withdraw_nuke govt_spendinginc_nuke {
ttest `var', by(`groupvar')
}   
restore



*Table A7*
preserve

	   
local vars individ_nodefend_nuke individ_conditional_nuke individ_withdraw_nuke individ_spendinginc_nuke  
local groupvar government_ever        

foreach var in  individ_nodefend_nuke individ_conditional_nuke individ_withdraw_nuke individ_spendinginc_nuke govt_nodefend_nuke govt_conditional_nuke govt_withdraw_nuke govt_spendinginc_nuke {
ttest `var', by(`groupvar')
}   
restore


*Figure A1a*
preserve
hist nuclear, percent graphregion(fcolor(white)) ytitle("% of Responses") discrete xlabel(1(1)5)
*eststo clear
restore

*Figure A1b*
preserve
replace country = "Neth." if country=="Netherlands"
graph hbar (mean) nuclear, over(country, sort(nuclear) label(labsize(*0.8))) graphregion(fcolor(white)) ytitle("Support for Nuclear Weapons")
*eststo clear
restore
